<template>
    <div>
        <p>商品名称：<input type="text" v-model="name"></p>
        <p>商品价格：<input type="text" v-model="price"></p>
        <p>商品img：<input type="text" v-model="img"></p>
        <p>商品状态：<input type="text" v-model="static"></p>
        <p>添加时间：<input type="text" v-model="addtime"></p>    
        <p>商品分类：<select v-model="fkey">
                        <option value="1">水果</option>
                        <option value="2">蔬菜</option>
                        <option value="3">冰激凌</option>
                    </select></p>
        <button @click="addg()">添加商品</button>
    </div>    
</template>

<script>
import axios from "axios"
export default {
    name:"addgoods",
    data() {
        return {
            name:"",
            price:"",
            img:"",
            static:"",
            addtime:"",
            fkey:""
        }
    },
    methods:{
        addg(){
            let formdata = new FormData()
            formdata.append("name",this.name)
            formdata.append("price",this.price)
            formdata.append("img",this.img)
            formdata.append("static",this.static)
            formdata.append("addtime",this.addtime)
            formdata.append("fkey",this.fkey)
            axios({
                url:"http://127.0.0.1:8000/app04/addgoods/",
                method:"post",
                data:formdata    
            }).then(res=>{
                if(res,data.code==200){
                    console.log(res.data)
                    alert(res.data.msg)
                }else{
                    console.log(res.data)
                    alert(res.data.msg)
                }
            })
        }
    }
}
</script>

<style>

</style>
